home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™ 1987-1994
/
MacHack™ '87
/
Utilities ƒ
/
Icon Utilities ƒ
/
Icon Creation
/
icons
< prev
next >
Wrap
Text File
|
1986-04-07
|
7KB
|
133 lines
Creating Your Own Icon
(c) 1985 by Fred Huxham
The following is adapted from the forthcoming book, Using the Macintosh
Toolbox, a book on writing Macintosh applications using the C programming
language, by Fred A. Huxham, Dave Burnard, and Jim Takatsuka, published by
SYBEX.
[Figures removed because this is an ASCII upload.]
Half the fun of writing your own application is creating and assigning its
desktop icon. For an application to have a custom icon, it must have a unique
signature, and, in its resource fork, a number of Finder-related resources.
In this section we will examine file signatures and all the Finder-related
resources an application needs in order to have a custom desktop icon. While
we are discussing each item required, we will be creating all the necessary
resources to assign a custom icon to a sample application named SoundCODE. To
create each of the Finder-related resources, we will use the Resource Editor
application. The application SoundCODE is shown in Figure 1 with its generic
application icon.
NOTE: To create a custom icon, you will need two applications, the Resource
Editor, and an application that will allow you to set a file's creator and
bundle bit (for example, the SetFile 2.0 desk accessory or the Fedit
application). A working knowledge of both the Resource Editor and the other
program you choose to use is assumed.
File Signatures and Bundle Bits
In order to have a custom icon, a Macintosh application must have a unique
signature that the Finder can identify it by. An application's signature,
often referred to as its creator, is a unique four-character sequence. The
creator must be unique in the respect that no other application on a currently
mounted disk can have the same four-character signature. In this example,
we'll set the creator of our application SoundCODE to be the four character
sequence FRED.
In addition to having a unique signature, an application must also have its
bundle bit set. The bundle bit, which is described briefly in Chapter 12, is
one of the Finder flags. When an application's bundle bit is set, the Finder
copies the application's, ICN#, FREF, BNDL, and version data resources, if
they have been created, into the Desktop file. The version data, ICN#, FREF,
and BNDL resources are the Finder-related resources we will learn how to
create shortly. The Desktop file is the invisible file on each disk that
keeps track of all the custom icons for files and programs on the same disk.
Once an application has a unique signature and its finder-related resources
have been copied to the desktop file, its custom icon will appear.
There are many applications and desk accessories that allow you to set a
file's creator and bundle bit. Fedit, a file and disk edit utility, and
SetFile 2.0, a desk accessory, are two programs that do the job. Figure 2
shows SetFile 2.0 with the application SoundCODE selected, with its creator
set to FRED and its bundle bit set. It is important, when setting a file's
creator and bundle bit, not to change any of its other fields or bits unless
you know what you're doing, since doing so can often cause lots of problems.
Now let's move onto the four Finder-related resources.
Version Data Resources
Each application must also have a version data resource, a special resource
that has the application's creator as its resource type. Thus, our
application, SoundCODE, will have a version data resource type of FRED. We
can create a resource of type FRED with the Resource Editor application. When
the resource type selector box of the Resource Editor appears on the screen,
as shown in Figure 3, instead of selecting one of the standard resource types,
type in the four-character sequence FRED. The resource doesn't need any data
entered into it and should have a resource ID of 0, as shown in Figure 4.
ICN# Resources
The ICN# or icon list resource is the actual custom icon for the application.
Creating an icon list resource is as easy as using fat bits in MacPaint.
Figure 5 shows the Resource Editor template for creating ICN# resources. The
icon on the upper-left is the application's desktop icon, and the icon on the
upper-right is its icon mask. The icon mask determines how the desktop icon
will appear when it is clicked with the mouse or moved across different
backgrounds. A common situation is to have the icon mask the same as the
icon. For SoundCODE we set the ICN# resource ID to be128.
FREF Resources
A FREF or file reference resource needs to know only the type of the file the
custom icon is being assigned to and the local ID of the custom icon. We can
determine a file's type with either Fedit or SetFile 2.0. If we look back at
Figure 2, we see that directly above the Creator field is the Type field. The
file type for SoundCODE, which is also the file type for any application
program, is APPL. Thus, for our sample program SoundCODE, we fill into the
FREF resource pictured in Figure 6 the type APPL and the icon local ID of 0.
The icon local ID can be any number so long as it is consistent with the local
ID that we specify in the BNDL resource, which we will do next.
The fileName field of a FREF indicates any file that should accompany the
application if it is copied to another disk. SoundCODE doesn't need any
associated files, so we have left the field blank. We have set SoundCODE's
FREF resource ID to be 128.
BNDL Resources
The last resource type an application needs for a custom icon is a BNDL, a
resource that serves to bundle everything together. Refer to Figure 7, which
shows the BNDL resource for SoundCODE, as we go over its fields one by one.
The first field, OwnerName, has to be set to the file's creator. For
SoundCODE, of course, the creator is FRED. Next, the ownerID is set equal to
the resource ID of the file's version data resource. The resource ID of
SoundCODE's FRED, or version data resource is 0, so we fill in the ownerID
field with 0. We don't set the numTypes field, the Resource Editor sets it
automatically.
Next let's set up the mapping between resources' local IDs and resource IDs.
These IDs can be set to whatever we want so long as we are consistent
throughout all of the Finder-related resources. First, we will set up the
mapping for the icon list resource of SoundCODE. We set the type field to
ICN# for icon list, and then set the local ID to 0, as we did in the FREF
resource. Finally we set the resource ID to 128 as we did when we created the
ICN#. We then do the same thing for the file reference resource, setting the
type field to FREF, the local ID to 0, and resource ID to 128. The value for
the # of this type field is not set by the programmer. We set the BNDL
resource to be 128.
Wrapping things up
Once SoundCODE's creator and bundle bit are set and all of the Finder-related
resources are created, its new custom icon should appear as in Figure 8.
If you follow the general directions we have just given for creating a new
icon and the new icon does not appear, it may be the case that the file or
application you are creating the icon for previously had a custom icon
assigned to it. To force the new icon to appear, double-click the mouse on
the Finder while holding down the Command and Option keys. This throws out
the old desktop file and recreates a new one, making your custom icon appear.